import LoginRoute from "/@ts/router/routes/login";
import { ROOT_ADMIN_PAGE_NAME, ROOT_PAGE_NAME } from "/@ts/router/constant";

import { AppRouteModule } from "/@ts/router/types";
export const useRouteStructure = (
  routes: AppRouteModule[],
): AppRouteModule[] => {
  let formatRouteMenuList: AppRouteModule[] = [];
  for (let index = 0; index < routes.length; index++) {
    const element: AppRouteModule = routes[index];
    if (element.children && element.children.length > 0) {
      formatRouteMenuList = formatRouteMenuList.concat(
        useRouteStructure(element.children),
      );
    } else {
      formatRouteMenuList.push(element);
    }
  }
  return formatRouteMenuList;
};

const modules = import.meta.glob("/src/router/routes/modules/*.ts", {
  eager: true,
});
const RouteModuleList: AppRouteModule[] = [];
Object.keys(modules).forEach((key) => {
  const mod = modules[key].default || {};
  const modList = Array.isArray(mod) ? [...mod] : [mod];
  RouteModuleList.push(...modList);
});
// 异步路由
export const RouteList = RouteModuleList; //没处理菜单的数据
// 异步路由
export const MenuRouter = useRouteStructure(RouteModuleList); //处理后的菜单数据


export const FilterRouterArr = (): Array<string> => {
  let data: any = RouteList.concat(LoginRoute);
  return data.map((res: any) => res.name);
};
// RouteModuleList.push(root)
// export const basicRoutes: AppRouteModule[] = [
//   ...LoginRoute,
//   ...RouteList,
// ];
